package paintObjects;

import interfaces.IPaintable;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.io.Serializable;

public class Square implements IPaintable, Serializable {

	private int xPosition;
	private int yPosition;
	private int xOrigin;
	private int yOrigin;
	private int width;
	private int height;
	private Color paintColor;

	public Square(int xPostion, int yPosition, Color color) {

		this.xPosition = xPostion;
		this.yPosition = yPosition;
		this.xOrigin = xPostion;
		this.yOrigin = yPosition;
		this.width = 0;
		this.height = 0;
		this.paintColor = color;
	}

	@Override
	public void painting(Graphics2D g, boolean tmp) {

		if (tmp) {

			float[] dash = { 5f, 5f };

			g.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT,
					BasicStroke.JOIN_BEVEL, 1f, dash, 0));

		} else {

			g.setStroke(new BasicStroke(2f));

		}

		g.setPaint(paintColor);
		g.drawRect(xPosition, yPosition, width, height);

	}

	@Override
	public void update(int x, int y) {
		if (x > xOrigin) {

			width = x - xOrigin;

		} else {

			width = xOrigin - x;
			xPosition = xOrigin - width;

		}

		if (y > yOrigin) {

			height = y - yOrigin;

		} else {

			height = yOrigin - y;
			yPosition = yOrigin - height;

		}

	}

}
